package com.linesum.code.retrofit;

import java.io.IOException;
import java.io.Serializable;
import java.util.Date;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.http.Body;
import retrofit2.http.POST;
import retrofit2.http.Query;

/**
 * 第一个retrofit
 * @author chenzf
 * @date 2017年6月7日下午2:11:28
 */
public class FirstRetrofit {
	private static final String BASE_URL = "http://192.168.251.17/service_request/newfenxiao/";

	public static void main(String[] args) throws IOException {
		Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();
		Retrofit retrofit = new Retrofit.Builder().baseUrl(BASE_URL)
				.addConverterFactory(GsonConverterFactory.create(gson)).build();
		DownloadGoods create = retrofit.create(DownloadGoods.class);
		Call<GoodsResponse> call = create.download("lsyc", new GoodsRequest("LSYJ", "乐商云集-趣分销"));
		GoodsResponse goodsResponse = call.execute().body();
		System.out.println(goodsResponse);
	}

	interface DownloadGoods {
		@POST("oneGoods")
		Call<GoodsResponse> download(@Query("appid") String appid, @Body GoodsRequest goodsRequest);
	}

	static class GoodsResponse implements Serializable {
		private static final long serialVersionUID = 5697490230729557155L;
		private String code;
		private String msg;
		private Date time;
		private String platform;

		public GoodsResponse(String code, String msg, Date time, String platform) {
			this.code = code;
			this.msg = msg;
			this.time = time;
			this.platform = platform;
		}

		public String getCode() {
			return code;
		}

		public void setCode(String code) {
			this.code = code;
		}

		public String getMsg() {
			return msg;
		}

		public void setMsg(String msg) {
			this.msg = msg;
		}

		public Date getTime() {
			return time;
		}

		public void setTime(Date time) {
			this.time = time;
		}

		public String getPlatform() {
			return platform;
		}

		public void setPlatform(String platform) {
			this.platform = platform;
		}

		@Override
		public String toString() {
			StringBuilder builder = new StringBuilder();
			builder.append("GoodsResponse [code=");
			builder.append(code);
			builder.append(", msg=");
			builder.append(msg);
			builder.append(", time=");
			builder.append(time);
			builder.append(", platform=");
			builder.append(platform);
			builder.append("]");
			return builder.toString();
		}

	}

	static class GoodsRequest implements Serializable {
		private static final long serialVersionUID = -8074265610379451255L;
		private String platform;
		private String storeName;

		public GoodsRequest(String platform, String storeName) {
			this.platform = platform;
			this.storeName = storeName;
		}

		public String getPlatform() {
			return platform;
		}

		public void setPlatform(String platform) {
			this.platform = platform;
		}

		public String getStoreName() {
			return storeName;
		}

		public void setStoreName(String storeName) {
			this.storeName = storeName;
		}

		@Override
		public String toString() {
			StringBuilder builder = new StringBuilder();
			builder.append("GoodsRequest [platform=");
			builder.append(platform);
			builder.append(", storeName=");
			builder.append(storeName);
			builder.append("]");
			return builder.toString();
		}

	}

}
